package com.sgb.kjwl.viewmodel.machine;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.model.entity.MachineRentInEntity;
import com.sgb.kjwl.repository.MachineRepertory;
import com.sgb.kjwl.view.ui.activity.leaseAsk.MachineInActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MLog;

import io.reactivex.functions.Consumer;

public class MachineInModel extends BaseViewModel {

    private final MachineInActivity machineInActivity;
    private final MachineRepertory machineRepertory;

    public MachineInModel(MachineInActivity machineInActivity, MachineRepertory machineRepertory) {
        this.machineInActivity = machineInActivity;
        this.machineRepertory = machineRepertory;
    }

    public void getInDetail(String id) {
        machineRepertory.getMachineInDetail(id).subscribe(new Consumer<BaseEntity<MachineRentInEntity>>() {
            @Override
            public void accept(BaseEntity<MachineRentInEntity> data) throws Exception {
                machineInActivity.showDetail(data.getData());
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                MLog.d(AppConstant.API_LOG, throwable.getMessage());
            }
        });
    }

}
